/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */

package cn.com.ksplatform.modules.system.auth.resourcemanager.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;

import cn.com.ksplatform.base.BaseModel;
import cn.com.ksplatform.modules.system.auth.menumanager.model.PlatMenu;
import cn.com.ksplatform.modules.system.auth.rolemanager.model.PlatRole;

/**
 * ClassName:PlatResource <br/>
 * Date: 2015年5月10日 下午1:26:20 <br/>
 * 
 * @author Mr.Luoxing
 * @version 1.0
 */
@Entity
@Table(name = "t_sys_resource")
public class PlatResource extends BaseModel {

	@Id
	@GenericGenerator(name = "systemUUID", strategy = "uuid")
	@GeneratedValue(generator = "systemUUID")
	@Column(name = "resoureid")
	private String resourceid;
	private String resourceName;
	private String link;
	private String enabled;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "menuId")
	@JsonIgnore
	private PlatMenu menu;

	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "t_sys_resouce_role", joinColumns = @JoinColumn(name = "resourceId"), inverseJoinColumns = @JoinColumn(name = "roleId"))
	private Set<PlatRole> roles = new HashSet<PlatRole>(0);

	public String getResourceid() {
		return resourceid;
	}

	public void setResourceid(String resourceid) {
		this.resourceid = resourceid;
	}

	public String getResourceName() {
		return resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public Set<PlatRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<PlatRole> roles) {
		this.roles = roles;
	}

	public PlatMenu getMenu() {
		return menu;
	}

	public void setMenu(PlatMenu menu) {
		this.menu = menu;
	}

	public String getEnabled() {
		return enabled;
	}

	public void setEnabled(String enabled) {
		this.enabled = enabled;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((resourceid == null) ? 0 : resourceid.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PlatResource other = (PlatResource) obj;
		if (resourceid == null) {
			if (other.resourceid != null)
				return false;
		} else if (!resourceid.equals(other.resourceid))
			return false;
		return true;
	}
	
	
}
